import useStore from '@/store'

export default {
    mounted(el, binding) {

        const { usePermissionStore } = useStore()
        const { value } = binding
        const all_permission = '*:*:*'

        const permissions  = usePermissionStore.auths || []
        
        if (value && Array.isArray(value) && value.length > 0) {
            const permissionFlag = value

            const hasPermission = permissions.some(permi => {
                return all_permission === permi || permissionFlag.includes(permi)
            } )

            if (!hasPermission) {
                el.parentNode && el.parentNode.removeChild(el)
            }
        } else {
            throw new Error('请设置权限标签值')
        }
    },
}